
public class AIbeta3D {

	Board3D board1;
	int player;
	int turn;
	int boardSize;
	AIbeta3D(int aBoardSize, int playerNum)
	{
		boardSize = aBoardSize;
		board1 = new Board3D(aBoardSize);
		player = playerNum;
		if(player == 0)
			turn = 1;
		else
			turn = 2;
	}
	
	
	public void makeMove(int boardsize, int[][][] boardstate, int[] lastmove, Long maxtime, int[] newmove)
	{
		if(lastmove[0] != -1 && lastmove[1] != -1)
			board1.insertPiece(lastmove[0], lastmove[1], lastmove[2], -player);

		
		if(board1.noMoreValidMoves(player))
		{
			System.out.println("THIS IS WRONGGGG");
			if(player == 1)
			{
				newmove[0] = -1;
				newmove[1] = 0;				
			}
			else
			{
				newmove[0] = 0;
				newmove[1] = -1;
			}
			return;
		}
		
		int x = 0;
		int y = 0;
		int z = 0;
		for(int i = 0; i < boardsize; i++)
		{
			for(int j = 0; j < boardsize; j++)
			{
				for(int k = 0; k<boardsize; k++)
				{
					if(board1.isValidMove(i,j,k,player))
					{
						x = i;
						y = j;
						z = k;
					}
				}
			}
		}
		newmove[0]=x;
		newmove[1]=y;
		newmove[2]=z;
		board1.insertPiece(x, y, z, player);
	}
	
	//returns array containing 2 elements
	//equal to number of moves for each player
	//[0] = number of black moves
	//[1] = number of white moves
	public int[] mobileCount(Board aBoard)
	{
		int numMoves[] = new int[2];
		int numBlack = 0;
		int numWhite = 0;
		for(int i =0; i< boardSize; i++)
		{
			for(int j = 0; j<boardSize; j++)
			{
				if(aBoard.isValidMove(i,j, 1))
				{
					numBlack++;
				}
			}
		}
		numMoves[0] = numBlack;
		numMoves[1] = numWhite;
		return numMoves;
	}
	
	public int[] stableCount(Board aBoard)
	{
		int stable[] = new int[2];
		return stable;
		
	}
	
	//returns a number between -100 and 100 depending on board state
	public int evaluateBoard(Board aBoard)
	{
		int mobilityRating;
		int boardValue = 0;
		int mobility[] = mobileCount(aBoard);
		int myMobility =0;
		int opponentsMobility = 0;
		if(player==1 )
		{
			myMobility = mobility[0];
			opponentsMobility = mobility[1];
			
		}
		else
		{
			myMobility = mobility[1];
			opponentsMobility = mobility[0];
		}
		
		int relativeMobility = myMobility - opponentsMobility;
		mobilityRating = relativeMobility * 5; //mobility weight
		boardValue += mobilityRating;
		
		int totalSize = boardSize * boardSize;
		int pieceRating = 0;
		int pieceDifference = 0;
		int myPieces =0;
		int opponentsPieces = 0;
		
		if(player==1 )
		{
			myPieces = aBoard.numBlack;
			opponentsPieces = aBoard.numWhite;
			
		}
		else
		{  
			myPieces = aBoard.numWhite;
			opponentsPieces = aBoard.numBlack;
		}
		pieceDifference = myPieces - opponentsPieces;
		
		if(aBoard.numPieces > totalSize-6)
		{
			pieceRating = pieceDifference * 5;
		}
		else if(aBoard.numPieces > 10 && myPieces <=3)
		{
			pieceRating = pieceDifference *4;
		}
		
		else if(aBoard.numPieces > totalSize-(1.5*boardSize))
		{
			pieceRating = pieceDifference *3;
		}
		else 
		{
			pieceRating = pieceDifference;
		}
		boardValue += pieceRating;
		
		return boardValue;
	}
	
}
